# -*- coding: utf-8 -*-

"""
youtubesearch

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from youtubesearch.api_helper import APIHelper
from youtubesearch.configuration import Server
from youtubesearch.controllers.base_controller import BaseController


class SimpleListSearchController(BaseController):

    """A Controller to access Endpoints in the youtubesearch API."""
    def __init__(self, config):
        super(SimpleListSearchController, self).__init__(config)

    def search(self,
               mtype,
               q,
               key):
        """Does a GET request to /search.

        Search API to search videos on Youtube based on a keyword.

        Args:
            mtype (string): The part parameter specifies a comma-separated
                list of one or more search resource properties that the API
                response will include. Set the parameter value to snippet.
            q (string): Keyword.
            key (string): auth key

        Returns:
            SearchEnum: Response from the API.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        # Prepare query URL
        _url_path = '/search'
        _query_builder = self.config.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'type': mtype,
            'q': q,
            'key': key
        }
        _query_builder = APIHelper.append_url_with_query_parameters(
            _query_builder,
            _query_parameters
        )
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare and execute request
        _request = self.config.http_client.get(_query_url)
        _response = self.execute_request(_request)
        self.validate_response(_response)

        decoded = _response.text

        return decoded
